package edu.gu.hajo.gcl.interp.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Hold local variables during a proc execution
 * Pushed on stack
 * @author hajo
 *
 */
class CallFrame {

	private String name; 
	private Map<String, String> localVars = new HashMap<String,String>();
	
	public CallFrame(String name, Map<String, String> localVars){
		this.name = name;
		// Important this is a copy !!
		this.localVars.putAll(localVars);
	}
	
	public void setVar(String name, String value){
		localVars.put(name, value);
	}
	
	public String getVar(String name) {
		return localVars.get(name);
	}
	
	@Override
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append(name + ":");
		Iterator<String> i = localVars.keySet().iterator();
		while( i.hasNext() ){
			String s = i.next();
			sb.append(s + "=");
			sb.append(localVars.get(s) + " ");
		}
		return sb.toString();
	}
}
